<template>
	<com-popup direction="bottom" :visible="visible" @hide="hide">
		<view class="popup-box" :style="{'background-color': skinColor.color_bg_2}" @touchmove.stop.prevent>
			<text class="fs-30 text-align-center" :style="{color: skinColor.color_3}">下载资源</text>
			<input
			class="popup-box-input"
			v-model="title"
			:style="{'background-color': skinColor.color_gap_1, 'color': skinColor.color_1}"
			placeholder="请输入下载文件名称" max-length="20" type="text" :placeholder-style="'color:' + skinColor.color_3" />
			<textarea
			class="popup-box-input"
			:style="{'background-color': skinColor.color_gap_1,'color': skinColor.color_1}"
			placeholder="请输入下载链接"
			:placeholder-style="'color:' + skinColor.color_3"
			:maxlength="-1"
			auto-height fixed v-model="url"></textarea>
			<view class="popup-box-input y-flex y-row y-align-center" :style="{'background-color': skinColor.color_gap_1,}" @tap="handleSelectDownloadPath">
				<text class="fs-28 mr-20" :style="{'color': skinColor.color_1}">下载位置</text>
				<text class="y-flex-1 fs-24" :style="{'color': skinColor.color_3}">{{downloadPath}}</text>
				<com-icon class="ml-20" name="right" :color="skinColor.color_1"></com-icon>
			</view>
			<view class="y-flex y-row y-align-center mt-45 ml-10" @tap="isAdult = isAdult ? 0 : 1" v-if="$store.getters['setting/GET_ADULT']">
				<com-icon size="40" :name="isAdult ? 'square_check_fill' : 'square'" :color="isAdult ? skinColor.color_blue : skinColor.color_3"></com-icon>
				<text class="fs-29 ml-5" :style="{color: skinColor.color_3}">包含敏感信息</text>
			</view>
			<view class="y-flex y-row mt-60">
				<com-button class="popup-box-btn y-flex-1" :bg-color="skinColor.color_3" :color="skinColor.color_3" radius="80rpx" size="30" plain value="取消下载" @click="hide"></com-button>
				<com-gap width="60rpx"></com-gap>
				<com-button class="popup-box-btn y-flex-1"  radius="80rpx" size="30" type="primary" value="确认下载" @click="handleDownloadConfirm"></com-button>
			</view>
		</view>
	</com-popup>
</template>

<script>
	import SkinColor from '@/assets/skin/index.js'
	import { openFileSystem } from '@/assets/js/native.js'
	export default {
		computed: {
			skinMode () {
				return this.$store.getters['setting/GET_SKIN_MODE']
			},
			skinColor () {
				return SkinColor[this.skinMode]
			},
			downloadPath () {
				return this.$store.getters['setting/GET_DOWNLOAD_PATH']
			}
		},
		data () {
			return {
				visible: false,
				title: '',//下载标题
				url: '',//下载链接
				isAdult: 0//是否敏感资源
			}
		},
		methods: {
			show ({title, url, isAdult}) {
				this.visible = true
				this.title = title || ''
				this.url = url || ''
				this.isAdult = isAdult || 0
			},
			hide () {
				this.visible = false
				this.title = ''
				this.url = ''
				this.isAdult = 0
			},
			handleDownloadConfirm () {
				if ( !this.title ) {
					uni.showToast({
						title: '请输入下载文件名称',
						icon: 'none'
					})
					return
				}
				if ( !this.url ) {
					uni.showToast({
						title: '请输入下载地址',
						icon: 'none'
					})
					return
				}
				this.$store.dispatch('download/create', {title: this.title, url: this.url, isAdult: this.isAdult})
				this.hide()
			},
			handleSelectDownloadPath () {
				openFileSystem({
					success: (folder) => {
						this.$store.commit('setting/SET_DOWNLOAD_PATH', folder.path)
					}
				})
			}
		}
	}
</script>

<style>
</style>